/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import gui.dialogs.Dialog_Prop;
import fvm.FVElement;
import fvm.FVModelData;
import gui.dialogs.Bound_GUI;
import gui.dialogs.StartSim;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import listener.CanvasEventListener;
import listener.ParentEventListener;

/**
 *
 * @author max
 */
public class GWS_GUI extends javax.swing.JFrame {

    ParentEventListener eventl;
    int act_timestep = 0;
    int tot_timesteps = 0;
    StartSim startsim;
    Dialog_Prop dprop;
    ArrayList<FVElement> alfve = null;
    DecimalFormat df = new DecimalFormat(".0000");
    NumberFormat formatter = new DecimalFormat( "0.###E0" );
    
    
    /**
     * Creates new form GWS_GUI
     */
    public GWS_GUI() {
        initComponents();
        canvas.addColorBar(colorbar);
        canvas.addCanvasEventListener(new CanvasEventListen());
       // jprogbar.setVisible(false);
        //auf 2. bildschirm ausgeben
        this.setLocation(2000, 100);
        jProgressBar1.setVisible(false);
                        jProgressBar1.setStringPainted(true);
                jProgressBar1.setBorderPainted(true);
                
                
    }
    
    
    public void addParentEventListener(ParentEventListener parent){eventl = parent;}
    public void paintModel(FVModelData fvmd){canvas.setModel(fvmd);}
    public void ModelisCreated(){
    jbut_suppp.setEnabled(true);
    jbut_fvr.setEnabled(true);
    jbut_assembl.setEnabled(true);
    jbut_colors.setEnabled(true);
    //colorbar = new JColorBar();
    colorbar.setulBound(0, 1);
    }
    public void calcAqui(){
     canvas.calculateAquilines();
    }
    public void enableSim(){jbut_sim.setEnabled(true);}
    public void enableSurf(){Btn_Surf.setEnabled(true);}
    public void enableAqui(){
        Btn_Aqui.setEnabled(true);
        canvas.calculateAquilines();
    }
    public void disableSim(){jbut_sim.setEnabled(false);}
    public void disableSurf(){Btn_Surf.setEnabled(false);}
    public void disableAqui(){Btn_Aqui.setEnabled(false);
    canvas.calculatedaqui = false;
    }
    public JColorBar getColorBar(){return colorbar;}
    public void setTimeSteps(int timesteps){tot_timesteps = timesteps;}
    public void setTimeStep(int timestep){
        if(timestep<=tot_timesteps){
        act_timestep = timestep;
        if(startsim != null){
        jTextField5.setText(Double.toString(act_timestep/startsim.getdt()));
        }
        else{jTextField5.setText("0");}
        canvas.setTimeStep(timestep);
        canvas.repaint();
        }}

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton6 = new javax.swing.JButton();
        jDialog1 = new javax.swing.JDialog();
        jDialog2 = new javax.swing.JDialog();
        jDialog3 = new javax.swing.JDialog();
        jOptionPane1 = new javax.swing.JOptionPane();
        jButton15 = new javax.swing.JButton();
        colorbar = new gui.JColorBar();
        canvas = new gui.JCanvas();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jbut_suppp = new javax.swing.JButton();
        jbut_fvr = new javax.swing.JButton();
        jbut_assembl = new javax.swing.JButton();
        jbut_sim = new javax.swing.JButton();
        Btn_Surf = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTA_prop = new javax.swing.JTextArea();
        BCNorth = new javax.swing.JButton();
        BCEast = new javax.swing.JButton();
        BCSouth = new javax.swing.JButton();
        BCWest = new javax.swing.JButton();
        Btn_Aqui = new javax.swing.JButton();
        jB_prop = new javax.swing.JButton();
        jProgressBar1 = new javax.swing.JProgressBar();
        jbut_colors = new javax.swing.JButton();
        jSlider2 = new javax.swing.JSlider();
        jSlider3 = new javax.swing.JSlider();

        jButton6.setText("jButton4");

        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jDialog2Layout = new javax.swing.GroupLayout(jDialog2.getContentPane());
        jDialog2.getContentPane().setLayout(jDialog2Layout);
        jDialog2Layout.setHorizontalGroup(
            jDialog2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jDialog2Layout.setVerticalGroup(
            jDialog2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jDialog3Layout = new javax.swing.GroupLayout(jDialog3.getContentPane());
        jDialog3.getContentPane().setLayout(jDialog3Layout);
        jDialog3Layout.setHorizontalGroup(
            jDialog3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jDialog3Layout.setVerticalGroup(
            jDialog3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        jButton15.setText("jButton8");
        jButton15.setEnabled(false);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("ModSimFV");

        javax.swing.GroupLayout colorbarLayout = new javax.swing.GroupLayout(colorbar);
        colorbar.setLayout(colorbarLayout);
        colorbarLayout.setHorizontalGroup(
            colorbarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1032, Short.MAX_VALUE)
        );
        colorbarLayout.setVerticalGroup(
            colorbarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 111, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout canvasLayout = new javax.swing.GroupLayout(canvas);
        canvas.setLayout(canvasLayout);
        canvasLayout.setHorizontalGroup(
            canvasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        canvasLayout.setVerticalGroup(
            canvasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jLabel2.setText("Länge:");

        jLabel3.setText("m");

        jLabel4.setText("Breite:");

        jTextField2.setColumns(6);
        jTextField2.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField2.setText("20");
        jTextField2.setToolTipText("");

        jLabel5.setText("m");

        jLabel6.setText("dy:");

        jTextField3.setColumns(6);
        jTextField3.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField3.setText("1");

        jLabel7.setText("dx:");

        jLabel8.setText("m");

        jTextField4.setColumns(6);
        jTextField4.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField4.setText("1");
        jTextField4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField4ActionPerformed(evt);
            }
        });

        jLabel9.setText("m");

        jLabel10.setText("t:");

        jTextField5.setColumns(6);
        jTextField5.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField5.setText("0");

        jLabel11.setText("s");

        jTextField6.setColumns(6);
        jTextField6.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextField6.setText("20");
        jTextField6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField6ActionPerformed(evt);
            }
        });

        jButton1.setText("Gebiet erstellen");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jButton1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jButton1KeyReleased(evt);
            }
        });

        jbut_suppp.setText("Stützstellen");
        jbut_suppp.setEnabled(false);
        jbut_suppp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbut_supppActionPerformed(evt);
            }
        });

        jbut_fvr.setText("Rahmen");
        jbut_fvr.setEnabled(false);
        jbut_fvr.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbut_fvrActionPerformed(evt);
            }
        });

        jbut_assembl.setText("Assemblieren");
        jbut_assembl.setEnabled(false);
        jbut_assembl.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbut_assemblActionPerformed(evt);
            }
        });

        jbut_sim.setText("Simuliation");
        jbut_sim.setEnabled(false);
        jbut_sim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbut_simActionPerformed(evt);
            }
        });

        Btn_Surf.setText("Oberfl. darstellen");
        Btn_Surf.setEnabled(false);
        Btn_Surf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Btn_SurfActionPerformed(evt);
            }
        });

        jButton8.setText("Fluss");
        jButton8.setEnabled(false);
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jTA_prop.setEditable(false);
        jTA_prop.setColumns(20);
        jTA_prop.setLineWrap(true);
        jTA_prop.setRows(5);
        jTA_prop.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jTA_prop.setEnabled(false);
        jScrollPane2.setViewportView(jTA_prop);

        BCNorth.setText("RB Oben");
        BCNorth.setEnabled(false);
        BCNorth.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BCNorthActionPerformed(evt);
            }
        });

        BCEast.setText("RB Rechts");
        BCEast.setEnabled(false);
        BCEast.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BCEastActionPerformed(evt);
            }
        });

        BCSouth.setText("RB Unten");
        BCSouth.setEnabled(false);
        BCSouth.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BCSouthActionPerformed(evt);
            }
        });

        BCWest.setText("RB Links");
        BCWest.setEnabled(false);
        BCWest.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BCWestActionPerformed(evt);
            }
        });

        Btn_Aqui.setText("Äquipoteniallinien");
        Btn_Aqui.setEnabled(false);
        Btn_Aqui.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Btn_AquiActionPerformed(evt);
            }
        });

        jB_prop.setText("Eigenschaften");
        jB_prop.setEnabled(false);
        jB_prop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jB_propActionPerformed(evt);
            }
        });

        jProgressBar1.setForeground(new java.awt.Color(0, 0, 255));

        jbut_colors.setText("Farben");
        jbut_colors.setEnabled(false);
        jbut_colors.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbut_colorsActionPerformed(evt);
            }
        });

        jSlider2.setMaximum(100000);
        jSlider2.setMinimum(1);
        jSlider2.setPaintLabels(true);
        jSlider2.setPaintTicks(true);
        jSlider2.setSnapToTicks(true);
        jSlider2.setToolTipText("");
        jSlider2.setValue(60000);
        jSlider2.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSlider2StateChanged(evt);
            }
        });

        jSlider3.setMaximum(10);
        jSlider3.setMinimum(1);
        jSlider3.setPaintLabels(true);
        jSlider3.setPaintTicks(true);
        jSlider3.setSnapToTicks(true);
        jSlider3.setValue(1);
        jSlider3.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSlider3StateChanged(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(colorbar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 1032, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbut_suppp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbut_fvr, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbut_assembl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbut_sim, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(Btn_Surf, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .addComponent(jB_prop, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .addComponent(Btn_Aqui, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbut_colors, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(canvas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(BCNorth, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(BCEast, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(BCSouth, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)
                            .addComponent(BCWest, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)
                            .addComponent(jSlider2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                            .addComponent(jSlider3, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel9)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel11)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addGap(22, 22, 22))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel9)
                        .addComponent(jLabel6)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel8)
                        .addComponent(jLabel10)
                        .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel11))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jLabel3)
                        .addComponent(jLabel4)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel5)
                        .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(BCNorth)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(BCEast)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(BCSouth)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(BCWest))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbut_assembl)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbut_sim)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbut_suppp)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jbut_colors)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbut_fvr)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(Btn_Aqui)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(Btn_Surf)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jB_prop)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 76, Short.MAX_VALUE)
                                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jSlider3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jSlider2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(canvas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(colorbar, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField4ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        disableAqui();
        disableSim();
        disableSurf();
        setplotqvisible(false);
        
        double sizex = Double.parseDouble(jTextField6.getText());
        double sizey = Double.parseDouble(jTextField2.getText());
        double dx = Double.parseDouble(jTextField4.getText());
        double dy = Double.parseDouble(jTextField3.getText());
        
        int n = (int)(sizex/dx);
        int m = (int)(sizey/dy);
        
        dx = sizex/n;
        dy = sizey/m;
        
        jTextField4.setText(Double.toString(dx));
        jTextField3.setText(Double.toString(dy));
        FVModelData fvmd = new FVModelData(n,m,sizex,sizey,dx,dy);
        eventl.Event_ModelCreated(fvmd);
        setTimeStep(0);
        setTimeSteps(0);
        jbut_assembl.setEnabled(true);
        jbut_sim.setEnabled(false);
        Btn_Surf.setEnabled(false);
        BCEast.setEnabled(true);
        BCWest.setEnabled(true);
        BCNorth.setEnabled(true);
        BCSouth.setEnabled(true);

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton1KeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            
            jButton1ActionPerformed(null);
        }
    }//GEN-LAST:event_jButton1KeyReleased

    private void jbut_supppActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbut_supppActionPerformed
        if(canvas.showstützstellen == true)canvas.showstützstellen = false;
    else canvas.showstützstellen = true;
     
    canvas.repaint();
    }//GEN-LAST:event_jbut_supppActionPerformed

    private void jbut_assemblActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbut_assemblActionPerformed
        eventl.Event_Assemble();
        
    }//GEN-LAST:event_jbut_assemblActionPerformed

    private void jbut_simActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbut_simActionPerformed
   
        startsim = new StartSim(this);
        eventl.Event_StartSim(startsim.gett(), startsim.getdt());        // TODO add your handling code here:
    }//GEN-LAST:event_jbut_simActionPerformed

    private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField6ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField6ActionPerformed

    private void jB_propActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jB_propActionPerformed

        
      
        dprop = new Dialog_Prop(this, true, alfve);
        repaint();
       
        
       
        
    }//GEN-LAST:event_jB_propActionPerformed

    
    
    
    
    private void jbut_fvrActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbut_fvrActionPerformed
        canvas.showfvframes = !canvas.showfvframes;
        canvas.repaint();
    }//GEN-LAST:event_jbut_fvrActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
     
        canvas.setplotqb(!canvas.getplotqb());
        canvas.repaint();
        
    }//GEN-LAST:event_jButton8ActionPerformed

    private void Btn_AquiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Btn_AquiActionPerformed
      
        
   canvas.showaquilines = !canvas.showaquilines;
   canvas.repaint();
        
        
    }//GEN-LAST:event_Btn_AquiActionPerformed

    private void jbut_colorsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbut_colorsActionPerformed

        canvas.showfvcolors = !canvas.showfvcolors;
        canvas.repaint();
    }//GEN-LAST:event_jbut_colorsActionPerformed

    private void BCNorthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BCNorthActionPerformed

        Bound_GUI b = new Bound_GUI(this,true,3, 0);
        b.setVisible(true);
        eventl.Event_NorthBound(b.gettyps(), b.getvals());
        
        canvas.repaint();
        
        
    }//GEN-LAST:event_BCNorthActionPerformed

    private void BCSouthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BCSouthActionPerformed
          Bound_GUI b = new Bound_GUI(this,true,3, 0);
        b.setVisible(true);
        eventl.Event_SouthBound(b.gettyps(), b.getvals());
        
        canvas.repaint();
    }//GEN-LAST:event_BCSouthActionPerformed

    private void BCEastActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BCEastActionPerformed
        Bound_GUI b = new Bound_GUI(this,true,1, 8);
        b.setVisible(true);
        eventl.Event_EastBound(b.gettyps(), b.getvals());
        
        canvas.repaint();
    }//GEN-LAST:event_BCEastActionPerformed

    private void BCWestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BCWestActionPerformed
         Bound_GUI b = new Bound_GUI(this,true,1, 12);
        b.setVisible(true);
        eventl.Event_WestBound(b.gettyps(), b.getvals());
        
        canvas.repaint();
    }//GEN-LAST:event_BCWestActionPerformed

    private void jSlider2StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSlider2StateChanged

        double v = (double)jSlider2.getValue()/10000;
        canvas.splotq = Math.exp(v)/1000;
        canvas.repaint();
        
    }//GEN-LAST:event_jSlider2StateChanged

    private void jSlider3StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSlider3StateChanged
        int v = jSlider3.getValue();
        canvas.aplotq = v;
        canvas.repaint();
    }//GEN-LAST:event_jSlider3StateChanged

    
    private void Btn_SurfActionPerformed(java.awt.event.ActionEvent evt) { 
    
    eventl.Event_plotSurface();
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(GWS_GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(GWS_GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(GWS_GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(GWS_GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GWS_GUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BCEast;
    private javax.swing.JButton BCNorth;
    private javax.swing.JButton BCSouth;
    private javax.swing.JButton BCWest;
    private javax.swing.JButton Btn_Aqui;
    private javax.swing.JButton Btn_Surf;
    private gui.JCanvas canvas;
    private gui.JColorBar colorbar;
    private javax.swing.JButton jB_prop;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton8;
    private javax.swing.JDialog jDialog1;
    private javax.swing.JDialog jDialog2;
    private javax.swing.JDialog jDialog3;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JOptionPane jOptionPane1;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSlider jSlider2;
    private javax.swing.JSlider jSlider3;
    private javax.swing.JTextArea jTA_prop;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JButton jbut_assembl;
    private javax.swing.JButton jbut_colors;
    private javax.swing.JButton jbut_fvr;
    private javax.swing.JButton jbut_sim;
    private javax.swing.JButton jbut_suppp;
    // End of variables declaration//GEN-END:variables


    public void setprogbarvisible(boolean bool){
    
        jProgressBar1.setVisible(bool);
    
    }
    
    public void setplotqvisible(boolean bool){jButton8.setEnabled(bool);
    }
    
    public void setprogbarrange(int u, int o){
    
    jProgressBar1.setMinimum(u);
    jProgressBar1.setMaximum(o);
    }
    public void setprogbar(int n){jProgressBar1.setValue(n);
    }
    

private class CanvasEventListen implements CanvasEventListener{

        @Override
        public void Element_clicked(FVElement fve) {
           
            alfve = new ArrayList<>();
            alfve.add(fve);
           String s = "Element "+fve.geti()+","+fve.getj()+"\n";
           s+="x: "+fve.getsupppoint().x+" y: "+fve.getsupppoint().y+"\n";
           s+="h: "+df.format(fve.gethk())+" ne: "+fve.getne()+"\n";
           s+="qx: "+formatter.format(fve.getqx(1))+" qy: "+formatter.format(fve.getqy(1));
           jTA_prop.setText(s);
           
           jB_prop.setEnabled(true);
           
        }

        @Override
        public void Elements_dragged(ArrayList<FVElement> alfves) {
            
           alfve = alfves;
           
            String s = "Elements: { ";
            for(int i = 0; i < alfve.size(); i++){
            
                s+= "("+alfve.get(i).geti()+","+alfve.get(i).getj()+")";
                if(i!=alfve.size()-1) s+="; ";
                if(i%2==0 && i!=alfve.size()-1)s+="\n";
            
            }
            s+=" }";
            jTA_prop.setText(s);
            
            jB_prop.setEnabled(true);
        }
    }


}
